﻿using System;
using System.Web.Http;
using PreeRegisterModel;
using System.Collections.Specialized;
using PreeRegisterBLL;
using PreeRegisterBLL.Security;

namespace PreeRegister_WebAPI.Controllers
{
    public class reportController : ApiController
    {
        [HttpPost]
        /// <summary>
        /// 获取检验报告条目 待开发
        /// </summary>
        /// <param name="any"></param>
        /// <returns></returns>
        public EncodeModel update(NameValueCollection any)
        {
            try
            {
                //获取JSON加密参数
                string head_json = CommonBLL.RequestGetParam("head").ToString();
                string body_json = CommonBLL.RequestGetParam("body").ToString();

                //拼装jsonData类
                EncodeModel encodeModel = new EncodeModel();
                encodeModel.head = head_json;
                encodeModel.body = body_json;

                //转化jsonData串
                string jsonData = csSerialize.ResponseInfo(encodeModel);
                ReportDetailResponseModel reportDetailResponseModel = new ReportDetailResponseModel();

                //解密头和内容信息
                string ErrMsg = "";
                string ReturnBodyJson = "";
                if (!ResultDecode.DecodeResult(jsonData, "", ref head_json, ref body_json, ref ErrMsg))
                {
                    //序列化返回内容类
                    ReturnBodyJson = csSerialize.ReportDetailResponseModel(reportDetailResponseModel);

                    //加密返回内容Json
                    return ResultDecode.EncodeResult(ReturnBodyJson);
                }

                //入口参数日志
                CommonBLL.WriteLog("report|detail|Post|\r\n" + body_json + "\r\n\r\n");

                //反序列化请求字符串
                ReportDetailRequestModel synBindRequestModel = csSerialize.ReportDetailRequestModel(body_json);
               
                //查询检验报告明细
                reportDetailResponseModel = ReportBLL.GetReportDetail(synBindRequestModel);

                //序列化返回内容类
                ReturnBodyJson = csSerialize.ReportDetailResponseModel(reportDetailResponseModel);

                //返回参数日志
                CommonBLL.WriteLog("report|detail|Return|\r\n" + ReturnBodyJson + "\r\n\r\n");

                return ResultDecode.EncodeResult(ReturnBodyJson);
            }
            catch (Exception err)
            {
                ReportDetailResponseModel reportDetailResponseModel = new ReportDetailResponseModel();
                reportDetailResponseModel.code = "0";
                reportDetailResponseModel.msg = err.ToString();
                //序列化返回内容类
                string ReturnBodyJson = csSerialize.ReportDetailResponseModel(reportDetailResponseModel);

                //返回参数日志
                CommonBLL.WriteLog("report|detail|Return|\r\n" + ReturnBodyJson + "\r\n\r\n");

                //加密返回内容Json
                return ResultDecode.EncodeResult(ReturnBodyJson);
            }
        }

        [HttpPost]
        /// <summary>
        /// 获取检验报告明细
        /// </summary>
        /// <param name="any"></param>
        /// <returns></returns>
        public EncodeModel detail(NameValueCollection any)
        {
            try
            {
                //获取JSON加密参数
                string head_json = CommonBLL.RequestGetParam("head").ToString();
                string body_json = CommonBLL.RequestGetParam("body").ToString();

                //拼装jsonData类
                EncodeModel encodeModel = new EncodeModel();
                encodeModel.head = head_json;
                encodeModel.body = body_json;

                //转化jsonData串
                string jsonData = csSerialize.ResponseInfo(encodeModel);
                ReportDetailResponseModel reportDetailResponseModel = new ReportDetailResponseModel();

                //解密头和内容信息
                string ErrMsg = "";
                string ReturnBodyJson = "";
                if (!ResultDecode.DecodeResult(jsonData, "", ref head_json, ref body_json, ref ErrMsg))
                {
                    //序列化返回内容类
                    ReturnBodyJson = csSerialize.ReportDetailResponseModel(reportDetailResponseModel);

                    //加密返回内容Json
                    return ResultDecode.EncodeResult(ReturnBodyJson);
                }

                //入口参数日志
                CommonBLL.WriteLog("report|detail|Post|\r\n" + body_json + "\r\n\r\n");

                //反序列化请求字符串
                ReportDetailRequestModel synBindRequestModel = csSerialize.ReportDetailRequestModel(body_json);

                //查询检验报告明细
                reportDetailResponseModel = ReportBLL.GetReportDetail(synBindRequestModel);

                //序列化返回内容类
                ReturnBodyJson = csSerialize.ReportDetailResponseModel(reportDetailResponseModel);

                //返回参数日志
                CommonBLL.WriteLog("report|detail|Return|\r\n" + ReturnBodyJson + "\r\n\r\n");

                return ResultDecode.EncodeResult(ReturnBodyJson);
            }
            catch (Exception err)
            {
                ReportDetailResponseModel reportDetailResponseModel = new ReportDetailResponseModel();
                reportDetailResponseModel.code = "0";
                reportDetailResponseModel.msg = err.ToString();
                //序列化返回内容类
                string ReturnBodyJson = csSerialize.ReportDetailResponseModel(reportDetailResponseModel);

                //返回参数日志
                CommonBLL.WriteLog("report|detail|Return|\r\n" + ReturnBodyJson + "\r\n\r\n");

                //加密返回内容Json
                return ResultDecode.EncodeResult(ReturnBodyJson);
            }
        }

    }
}
